package command.menu.project;

import javax.xml.bind.annotation.XmlTransient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import util.Utils;
import model.Project;
import model.User;
import controller.ApplicationController;

public class CreateProjectCommand extends AbstractProjectCommand {

	@XmlTransient
	private static final Logger log = LoggerFactory.getLogger(CreateProjectCommand.class);	

	private String userName;
	private String projectName;
	private String projectDescription;

	protected CreateProjectCommand() {
		super();
	}

	/*
	 * username must exist before use
	 */
	public CreateProjectCommand(String userName, String projectName,
			String projectDescription) {
		super();
		this.userName = userName;
		this.projectName = projectName;
		this.projectDescription = projectDescription;
	}

	@Override
	public void executeLocal(ApplicationController applicationController) {
		log.debug("Executing command : CreateProjectCommand ...");
		// use getUserByName, return createdOutOfProjectUser from controller
		// if creating project with new username
		User user = applicationController.getUserByName(userName);
		Project project = new Project(Utils.getUID(), projectName, projectDescription, user);
		applicationController.getModel().getProjects().add(project);
		applicationController.getModel().setCurrentProject(project);
		log.debug("Executing command : CreateProjectCommand DONE");
	}
	
	@Override
	public void executeRemote(ApplicationController applicationController) {
		
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public String getProjectDescription() {
		return projectDescription;
	}

	public void setProjectDescription(String projectDescription) {
		this.projectDescription = projectDescription;
	}
	
}
